using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using webapp4U.BOL;


namespace webapp4U.UI
{
    public partial class WebMaster_Default : System.Web.UI.Page
    {
         string strFilePath;
        protected void Page_Load(object sender, EventArgs e)
        {
            strFilePath = Request.PhysicalApplicationPath + "UserUpload/WebURL.txt";

            if (!Page.IsPostBack)
                txtMarquee.Text = ReadTextFile(strFilePath).Replace("&nbsp;", " ");
        }


        public string ReadTextFile(string filePath)
        {
            if (!System.IO.File.Exists(filePath))
            {
                return "";
            }

            using (StreamReader sr = System.IO.File.OpenText(filePath))
            {
                StringBuilder text = new StringBuilder();
                String input;
                while ((input = sr.ReadLine()) != null)
                {
                    text.AppendLine(input);
                }
                sr.Close();
                return text.ToString();
            }
        }


        public void CreateTextFile(string filePath, string text)
        {
            using (StreamWriter sw = System.IO.File.CreateText(filePath))
            {
                sw.WriteLine(text);
                sw.Close();
            }
        }

        protected string TextReplace(string Text)
        {
            //Text = Text.Replace(Environment.NewLine,"\n");
            return Text;
        }

        protected void btSave_Click(object sender, EventArgs e)
        {
            CreateTextFile(strFilePath, TextReplace(txtMarquee.Text.Trim()));
        }
    }
}